package com.wmh.baseservice.system.controller;

import com.wmh.baseservice.common.annotation.parameterverify.ParameterVerify;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.system.service.SysLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wmh generator
 * @since 2022-01-17
 */
@Api(tags = "系统-行政区域")
@RestController
@RequestMapping(value = "system/sysLocation", produces = "text/plain;charset=utf-8")
public class SysLocationController {

    @Resource
    private SysLocationService sysLocationService;


    @ApiOperation("根据地址id列表得到其中id的最子级id")
    @PostMapping("getSubIdByPidList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = List.class, name = "pIds", value = "pIds", required = false),
    })
    @ParameterVerify(notNull = "pIds")
    public String getSubIdListByParentId(String pIds){
        ArrayList<Integer> list = new ArrayList<>();
        for (String s : pIds.split(",")) {
            list.add(Integer.valueOf(s));
        }
        return ReturnBody.success(sysLocationService.getSubIdListByParentId(list));
    }

    @ApiOperation("根据地区id列表得到当前列表的最父级名称列表")
    @PostMapping("getParentNamesByIds")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = List.class, name = "pIds", value = "pIds", required = false),
    })
    @ParameterVerify(notNull = "ids")
    public String getParentNamesByIds(String ids){
        ArrayList<Integer> list = new ArrayList<>();
        for (String s : ids.split(",")) {
            list.add(Integer.valueOf(s));
        }
        return ReturnBody.success(sysLocationService.getParentNamesByIds(list));
    }


}
